# -*- coding: utf-8 -*-
"""
author:xiang
date:2023-02-12
desc: 
sample: 
"""
from backend.utils.RequestUtil import RequestUtil


def test_check():
    api = RequestUtil()
    api.send_request("get", "http://82.156.74.26:9088/pinter/com/getSku?id=1",
                     verification='$.code=0', case_desc='json检查点测试', )
    print(f"当前接口测试结果{api.get_result()}")

    api.send_request("get", "http://www.baidu.com",
                     verification='<title>(.+?)</title>=百度一下，你就知道', case_desc='正则检查点测试', )
    print(f"当前接口测试结果{api.get_result()}")

def test_correlation():
    api = RequestUtil()
    # api.send_request("get", "http://82.156.74.26:9088/pinter/com/getSku?id=1",
    #                  verification='$.code=0', case_desc="json提取",
    #                  extract="skuId=$.data.skuId")
    # print(f"当前接口测试结果{api.get_result()},  全局变量{api.get_variable()}")
    #
    # api.send_request("get", "http://www.baidu.com",
    #                  case_desc="html数据提取",
    #                  extract="title=<title>(.+?)</title>")
    # print(f"当前接口测试结果{api.get_result()},  全局变量{api.get_variable()}")

    data = {"param": '{"skuId":${skuId}, "num": 10, "desc":${title}'}
    api.send_request("post", "http://82.156.74.26:9088/pinter/com/login",
                     verification='$.code=0',
                     data=data,case_desc="参数替换")
    print(f"当前接口测试结果{api.get_result()},  全局变量{api.get_variable()}")

def test_api():
    api = RequestUtil()
    api.send_request("get", "http://172.16.8.56:8000/test_manage/case_module/?project_belong=1",
                     verification='', case_desc="", extract="")
    print(f"当前接口测试结果{api.get_result()},  全局变量{api.get_variable()}")

def test_sc():
    sc = RequestUtil()
    data = {
      "a": "zh-CN",
      "c": 10201,
      "login_token": "g%2BFBxb0Md5lI4O3wVDH3bSIzNwNqfbgHEGAuZgFfrG%2FHQ1%2Bg0woPyqh4ksdIeO5Vt2BUXZl1a0LsecxORqbMnTCZ7aJj%2BhliL55EJSEywcXGR6wAH13pdJy%2FDhyQFo2F0xH8GvgmcE%2F9sBFIAMXdBsH8XdoWmSuwim6Hc02sbi7IRjQTcOiSj4CyYkXDJQChwpnl67Q%2FUYWNZt7hSELsTcU7OS8%3D"
    }
    user = {
      "c": 10205,
      "name": "NO978"
    }
    sc.create_conn("ws://192.168.1.147:8092/drw/20081", data, case_desc="sc连接测试")
    sc.send_msg(user)


if __name__ == '__main__':
    # test_correlation()
    test_sc()
